const Koa = require("koa")
const koaRouter = require("koa-router")()
const router = require("./router/index")
const http = require("http")
const serve = require('koa-static')
const passport = require('koa-passport')
const session = require('koa-session')
const bodyParser = require('koa-bodyparser')

require("./social-login/auth")

const app = new Koa()

const dev = !(app.env === "production")

// Build only in dev mode
if (dev) {
    // logger
    app.use(async function (ctx, next) {
        const start = new Date()
        await next()
        const ms = new Date() - start
        console.log(`koa:render ${ctx.method} ${ctx.url} - ${ms}ms`)
    })
}

app.use(bodyParser())
app.keys = ['secret']
app.use(session({}, app))
//Auth
app.use(passport.initialize())
app.use(passport.session())

//http路由
router(koaRouter, app)
app.use(koaRouter.routes())

app.use(serve('./static'))

app.listen(3000, "0.0.0.0", ()=>{
  console.log( `Server listening on 0.0.0.0:3000` )
})